package org.lex.ftp.ui.prefs;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.lex.ftp.util.prefs.FileAction;
import org.lex.swing.Swings;
import org.lex.swing.util.CenterPane;


public class FileActionSelectorPane extends JPanel {
	private JLabel promptLabel = null;
	private JLabel sourcePromptLabel = null;
	private JLabel sourceLabel = null;
	private JLabel destPromptLabel = null;
	private JLabel destLabel = null;
	private JComboBox actionsComboBox = null;
	private JButton okButton = null;
	private JPanel gluePane = null;

	public static void main(String[] args) {
		Swings.show(new CenterPane(new FileActionSelectorPane()), false);
	}

	public FileActionSelectorPane() {
		super();
		initialize();
	}

	private JButton getOkButton() {
		if (okButton == null) {
			okButton = new JButton();
			okButton.setText("OK");
		}
		return okButton;
	}

	private void initialize() {
		GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
		gridBagConstraints7.gridx = 0;
		gridBagConstraints7.fill = GridBagConstraints.BOTH;
		gridBagConstraints7.weightx = 10.0;
		gridBagConstraints7.weighty = 10.0;
		gridBagConstraints7.gridwidth = 2;
		gridBagConstraints7.gridy = 5;
		GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
		gridBagConstraints6.gridx = 1;
		gridBagConstraints6.gridy = 6;
		GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
		gridBagConstraints5.fill = GridBagConstraints.NONE;
		gridBagConstraints5.gridy = 6;
		gridBagConstraints5.weightx = 1.0;
		gridBagConstraints5.anchor = GridBagConstraints.EAST;
		gridBagConstraints5.insets = new Insets(0, 0, 0, 12);
		gridBagConstraints5.gridx = 0;
		GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
		gridBagConstraints4.gridx = 0;
		gridBagConstraints4.gridwidth = 2;
		gridBagConstraints4.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints4.weightx = 10.0;
		gridBagConstraints4.insets = new Insets(0, 0, 12, 0);
		gridBagConstraints4.gridy = 4;
		destLabel = new JLabel();
		destLabel.setText("Dest");
		GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
		gridBagConstraints3.gridx = 0;
		gridBagConstraints3.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints3.gridwidth = 2;
		gridBagConstraints3.weightx = 10.0;
		gridBagConstraints3.insets = new Insets(0, 0, 6, 0);
		gridBagConstraints3.gridy = 3;
		destPromptLabel = new JLabel();
		destPromptLabel.setText("With this one?");
		GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
		gridBagConstraints2.gridx = 0;
		gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints2.weightx = 10.0;
		gridBagConstraints2.gridwidth = 2;
		gridBagConstraints2.insets = new Insets(0, 0, 12, 0);
		gridBagConstraints2.gridy = 2;
		sourceLabel = new JLabel();
		sourceLabel.setText("Source");
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
		gridBagConstraints1.gridx = 0;
		gridBagConstraints1.gridwidth = 2;
		gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints1.weightx = 10.0;
		gridBagConstraints1.insets = new Insets(0, 0, 6, 0);
		gridBagConstraints1.gridy = 1;
		sourcePromptLabel = new JLabel();
		sourcePromptLabel.setText("Would you like to replace the existing file");
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridwidth = 2;
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 10.0;
		gridBagConstraints.insets = new Insets(0, 0, 18, 0);
		gridBagConstraints.gridy = 0;
		promptLabel = new JLabel();
		promptLabel.setText("<html>Prompt:<br>Message</html>");
		this.setSize(300, 200);
		this.setLayout(new GridBagLayout());
		this.add(promptLabel, gridBagConstraints);
		this.add(sourcePromptLabel, gridBagConstraints1);
		this.add(sourceLabel, gridBagConstraints2);
		this.add(destPromptLabel, gridBagConstraints3);
		this.add(destLabel, gridBagConstraints4);
		this.add(getActionsComboBox(), gridBagConstraints5);
		this.add(getOkButton(), gridBagConstraints6);
		this.add(getGluePane(), gridBagConstraints7);
	}

	private JComboBox getActionsComboBox() {
		if (actionsComboBox == null) {
			actionsComboBox = new JComboBox(FileAction.displayNames());
		}
		return actionsComboBox;
	}

	private JPanel getGluePane() {
		if (gluePane == null) {
			gluePane = new JPanel();
			gluePane.setLayout(new GridBagLayout());
		}
		return gluePane;
	}
}
